package com.qf.lanzhou.blog.api.service.impl;

import com.qf.lanzhou.blog.api.dao.ArticleDao;
import com.qf.lanzhou.blog.api.dao.Impl.ArticleDaoImp;
import com.qf.lanzhou.blog.api.pojo.entity.Article;
import com.qf.lanzhou.blog.api.pojo.entity.Page;
import com.qf.lanzhou.blog.api.service.ArticleService;

import java.util.List;

/**
 * @author Yeach-chen
 * @ClassName ArticleServiceImp
 */
public class ArticleServiceImp implements ArticleService {
    private ArticleDao articleDao= new ArticleDaoImp();

    @Override
    public List<Article> checkArticle(String inter) {
        System.out.println("1111");
        List<Article> articleList = articleDao.getArticleList(inter);
        System.out.println("2222");
        if (articleList.size()==0){
            throw new  RuntimeException ("无您搜索内容！");
        }
        return articleList;
    }

    @Override
    public List<Article> getArticleList() {
        List<Article> articleList = articleDao.getAllArticleList();
        if (articleList.size()==0){
            throw new RuntimeException("系统维护中..");
        }
        return articleList;
    }

    @Override
    public int AddArticleView(int num) {
        int result = articleDao.AddView(num);
        return result;
    }

    @Override
    public List<Article> checkArticlePage(String inster, Integer integer) {
        Page page = new Page(integer,20);
        List<Article> listPage = articleDao.getArticleListPage(inster, page);
        return listPage;
    }

    @Override
    public Integer getCount(String inster) {
        Long aLong = articleDao.getarticleListCount(inster);
        String s = Long.toString(aLong);
        Integer decode = Integer.decode(s);
        return decode;
    }

    @Override
    public Article getArticlePar(int ArticleId) {
        Article articleParam = articleDao.getArticleParam(ArticleId);
        return articleParam;
    }
}
